package servlet;

import bean.Comment;
import dao.entity.CommentDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "commentUpdateServlet", value = "/ccupdate")
public class CommentUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //取数
        String ccid = (String) request.getParameter("ccid");
        String cid = (String) request.getParameter("cid");
        String cname = (String) request.getParameter("cname");
        String cc_time = (String) request.getParameter("cc_time");
        String content = (String) request.getParameter("content");
        //修改数据
        CommentDaoImpl cdi = new CommentDaoImpl();
        Comment c = new Comment();
        c.setCcid(ccid);
        c.setCid(cid);
        c.setCname(cname);
        c.setCc_time(cc_time);
        c.setContent(content);
        int n = cdi.updateComment(c);
        if(n==1){
            request.setAttribute("message","修改成功!");
        }else {
            request.setAttribute("message","修改失败!");
        }
        request.getRequestDispatcher("result.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
